package demo1.web.servlet.userMaiapi;

import demo1.dao.Mapper.goodsMapper;
import demo1.pojo.goods;
import demo1.pojo.userMai;
import demo1.dao.sql.goodssql;
import demo1.service.userMaiService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.ResultSet;

@WebServlet("/showGoodsXiaoLiang")
public class showGoodsXiaoLiang extends HttpServlet {//展示销量
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset = utf-8");
        int goodsID = Integer.parseInt(req.getParameter("goodsID"));
        //获取session对象
        HttpSession session = req.getSession();
        Object userObject = session.getAttribute("users");
        userMai users = (userMai) userObject;

        goods good = null;
        try {
            userMaiService show = new userMaiService();
            good = show.modifyGoodsNum1(users.getId(), goodsID);//展示所有的商品
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        req.setAttribute("good", good);//把数据存储起来
        req.getRequestDispatcher("showGoodsXiaoLiang.jsp").forward(req, resp);//转发到另一个界面
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
